package com.ilink.groundservice.controller;/**
 * <h3>iLink-java-backend-zhangbo2</h3>
 *
 * @Description <p>模型广场与前端的交互接口</p>
 * @Author ZhangBo
 * @Date 2024-09-16 18:55
 **/

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ilink.groundservice.entity.VO.model.ModelHomepageResponse;
import com.ilink.groundservice.entity.VO.model.ModelInformationResponse;
import com.ilink.groundservice.service.model.ModelLangflowService;
import com.ilink.groundservice.service.model.ModelTagsService;
import com.ilink.ilinkapi.dto.ground.model.ModelMetadataRequest;
import com.ilink.ilinkcommon.domain.R;
import java.util.Arrays;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.json.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ilink.ilinkcommon.log.method.MethodLog;
/**
 * @ClassName ModelController
 * @Description 模型广场与前端的交互接口
 * @Author ZhangBo
 * @Date 2024-09-16 18:55
 **/
@Slf4j
@RequestMapping("/ground/model")
@RestController
@RequiredArgsConstructor
public class ModelController {
    private final ModelLangflowService modelLangflowService;
    private final ModelTagsService modelTagsService;

    /**
     * @Author ZhangBo
     * @Description 分页返回模型广场元数据
     * @Date 21:07 2024/9/17
     * @Param [request]
     * @return com.ilink.ilinkcommon.domain.R
     **/
    @MethodLog(value = "分页查询模型广场元数据信息")
    @PostMapping("/get_model_metadata")
    public R getModelMetadata(@RequestBody ModelMetadataRequest request){
        try {
            IPage<ModelHomepageResponse> responseIPage = modelLangflowService.getModelMetadata(request);
            if(responseIPage != null){
                return R.ok("分页返回模型广场元数据", responseIPage);
            }else{
                return R.error("未查询到模型广场元数据");
            }
        }catch (Exception e){
            log.error(e.getMessage());
            return R.error(e.getMessage());
        }
    }

    /**
     * @Author ZhangBo
     * @Description 返回模型广场详情信息
     * @Date 21:25 2024/9/17
     * @Param [jsonString]
     * @return com.ilink.ilinkcommon.domain.R
     **/
    @MethodLog(value = "获取模型广场详情信息")
    @PostMapping("/get_model_information")
    public R getModelMetadata(@RequestBody String jsonString){
        try {
            JSONObject jsonObject = new JSONObject(jsonString);
            String targetId = jsonObject.getString("targetId");

            ModelInformationResponse response = modelLangflowService.getModelInformation(
                Long.valueOf(targetId));
            if(response != null){
                return R.ok("分页返回模型广场详情信息", response);
            }else{
                return R.error("未查询到模型广场详情信息");
            }
        }catch (Exception e){
            log.error(e.getMessage());
            return R.error(e.getMessage());
        }
    }
    @MethodLog(value = "获取模型广场最常使用的八个标签")
    @GetMapping("/get_common_model_tags")
    public R getCommonDatasetTags(){
        try {
            // 直接定义一个固定的列表
            List<String> fixedResult = Arrays.asList(
                "阿里", "百度", "科大讯飞", "腾讯",
                "字节跳动", "智谱AI", "MiniMax", "商汤","百川"
            );

            // 返回固定列表
            return R.ok("模型广场最常用的八个标签", fixedResult);
        } catch(Exception e){
            return R.error("错误：" + e.getMessage());
        }
    }

}
